package com.qf.controller;

import com.qf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller

public class controller {
    @RequestMapping("/upload")
    public  String upload(String name, @RequestParam("fl") MultipartFile img){
        System.out.println("name:"+name);
        String imgName = img.getName();//文件名
        System.out.println("imgName:"+imgName);
        String originalFilename = img.getOriginalFilename();//属性
        System.out.println("filename="+originalFilename);
        long imgSize = img.getSize();
        System.out.println("imgSize:"+imgSize);
        System.out.println("upload执行了");
        System.out.println("这是第二次在git中提交");
        try {
            img.transferTo(new File("D:\\QMDownload\\"+originalFilename));
        } catch (IOException e) {
            e.printStackTrace();
        }
return  "index";
    }


    @ResponseBody
     @RequestMapping("/test")
    public List<User> test(){
        User  user1=new User("zhangsan",11);
         User  user2=new User("lisi",2);
         List list=new ArrayList();
         list.add(user1);
         list.add(user2);
         return list;
     }
}
